﻿#include "stdafx.h"
#include "SheetView.h"
#include "ui_SheetView.h"
#include "BaseInclude.h"
#include "FrameInclude.h"
#include "LoginUserInfo.h"

#include <QDateTime>
#include <QGraphicsView>
#include <QDomDocument>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QRegExp>
#include <QMessageBox>
#include <QtNetwork>
#include <QMediaPlaylist>

enum PTZACTION//云台方向控制
{
	PTZ_CMD_ZOOM_IN = 11,		/* 焦距以速度SS变大(倍率变大) */
	PTZ_CMD_ZOOM_OUT = 12,		/* 焦距以速度SS变小(倍率变小) */
	PTZ_CMD_FOCUS_NEAR = 13,		/* 焦点以速度SS前调*/
	PTZ_CMD_FOCUS_FAR = 14,		/* 焦点以速度SS后调*/
	PTZ_CMD_IRIS_OPEN = 15,		/* 光圈以速度SS扩大*/
	PTZ_CMD_IRIS_CLOSE = 16,		/* 光圈以速度SS缩小*/
	PTZ_CMD_TILT_UP = 21,	    /* 云台以SS的速度上仰*/
	PTZ_CMD_TILT_DOWN = 22,		/* 云台以SS的速度下俯*/
	PTZ_CMD_PAN_LEFT = 23,		/* 云台以SS的速度左转*/
	PTZ_CMD_PAN_RIGHT = 24,		/* 云台以SS的速度右转*/
	PTZ_CMD_UP_LEFT = 25,		/* 云台以SS的速度上仰和左转*/
	PTZ_CMD_UP_RIGHT = 26,		/* 云台以SS的速度上仰和右转*/
	PTZ_CMD_DOWN_LEFT = 27,		/* 云台以SS的速度下俯和左转*/
	PTZ_CMD_DOWN_RIGHT = 28,		/* 云台以SS的速度下俯和右转*/
	PTZ_CMD_PAN_AUTO = 29,		/* 云台以SS的速度左右自动扫描*/
	PRESET_CMD_SET_PRESET = 8,		/* 设置预置点*/
	PRESET_CMD_CLE_PRESET = 9,		/* 清除预置点*/
	PRESET_CMD_GOTO_PRESET = 39,	/* 转到预置点*/
};

SheetView::SheetView(int sheetid, int sheetBox, QWidget *parent)
	: iSheetId(sheetid), iSheetBox(sheetBox), QWidget(parent), http(this)
{
	ui = new Ui::SheetView();
	ui->setupUi(this);
	ui->stackedWidget->setCurrentIndex(0);
	if (1 == iSheetBox)
	{
		ui->btnPlayBack->setVisible(false);
	}
	else
	{
		ui->stackedWidget->setCurrentIndex(1);
		ui->btnStart->setVisible(false);
		ui->btnPause->setVisible(false);
	}

	connect(&http, SIGNAL(responseReady()), this, SLOT(getResponse()));
	QObject::connect(ui->axWidgetPlayBack, SIGNAL(Notify(int, int, int, QString)), this, SLOT(NotifyPlatformplaybackctrl(int, int, int, QString)));

	m_dwTransTaskId = -1;

	for (int i = 0; i < DEMO_SHOW_USER_NUM; i++)
	{
		m_iUserID[i] = -1;
	}
	initialise();
	strCurrentCamIndex = "";
	strPreviousSelectText = "";
	strStartTime = "";
	hikTgt = "";
	//ui->btnPreview->setVisible(false);
}

SheetView::~SheetView()
{
	delete pMusicPlayer;
	pMusicPlayer = Q_NULLPTR;
	delete playList;
	playList = Q_NULLPTR;

	m_AnyChatSDK.Release();
	ui->axWidgetSheet->dynamicCall("CloseSheet()");
	delete ui;
}

void SheetView::timerEvent(QTimerEvent *event)
{
	killTimer(iTimerId);
	iCurrentRow++;
	CHK_EXP_END(iCurrentRow >= dsRecordTimer.rowCount());

	QString strCamIndexCode = dsRecordTimer.getCollectStr(iCurrentRow, "CAMINDEXCODE");
	int iSortId = dsRecordTimer.getCollectInt(iCurrentRow, "SORTID");
	QString strTotalText = dsRecordTimer.getCollectStr(iCurrentRow, "TOTALTEXT");
	int iLastIndex = strTotalText.lastIndexOf("|");
	QString curTime = strTotalText.mid(iLastIndex + 1);
	QTime tTime = QTime::fromString(curTime, "hh:mm:ss");

	int iTime = tCurBeginTime.msecsTo(tTime);
	tCurBeginTime = tTime;

	ui->axWidgetSheet->dynamicCall("SetCurrentSelectRow(int,int)", iSheetId, iSortId);
	iTimerId = startTimer(iTime);
	if (strCamIndexCode!=strCurrentCamIndex)
	{
		strCurrentCamIndex = strCamIndexCode;
		listSheetCamInfo.removeAt(0);
		service_sdkLogin(SERVICE_LOGIN);
	}
}

//================================================================================================================================================
void SheetView::on_btnPlayBack_clicked()
{
	QRecord dsRecord;
	QString strLySql = QString("SELECT LY FROM JXD7_YDCZP_CZPINFO WHERE SHEETID = %1").arg(iSheetId);
	if(!dsRecord.select(strLySql))
	{
		qMsgBoxError(tr("read JXD7_YDCZP_CZPINFO failed!"));
		return;
	}

	if(dsRecord.rowCount()>0)
	{
		QString strLY = dsRecord.getCollectStr(0, "LY");
		listLY = strLY.split(",");
		for (int i = 0; i < listLY.count();i++)
		{
			if (listLY[i]=="null")
			{
				listLY.removeAt(i);
				i--;
			}
		}
	}
	else
	{
		qMsgBoxAlert(tr("not have the ly file!"));//没有相关录音文件
		return;
	}
	
	if (listLY.count() == 0)
	{
		qMsgBoxAlert(tr("ly file is null!"));//录音文件为null
		return;
	}

	startRequest();
}

void SheetView::on_btnClose_clicked()
{
	//QRegExp rx(tr("([^0-z]+[0-F]{4})cong(.{2,6})gaiwei(.{2,8})"));
	//int pos = rx.exactMatch(tr("DuJiao2B23CongKaiGuanJianXiuGaiWeiLengBeiYong"));
	//QStringList list = rx.capturedTexts();
	emit closeSheetSignal(-1);
}

void SheetView::on_btnStart_clicked()
{
	const char* info = "##start##";
	if ((m_AnyChatSDK.SendTextMessage(-1, NULL, (LPCTSTR)info, sizeof(*info))) != 0)  //发送成功
	{
		qMsgBoxInfo("start failed!");
	}
	ui->btnStart->setVisible(false);
	ui->btnPause->setVisible(true);
}

void SheetView::on_btnPause_clicked()
{
	const char* info = "##pause##";
	if ((m_AnyChatSDK.SendTextMessage(-1, NULL, (LPCTSTR)info, sizeof(*info))) != 0)  //发送成功
	{
		qMsgBoxInfo("pause failed!");
	}
	ui->btnStart->setVisible(true);
	ui->btnPause->setVisible(false);
}

void SheetView::on_btnEnterRoom_clicked()
{
	initConnect();
	userLogin();
}

void SheetView::on_btnUp_pressed()
{
	ptzControl(PTZ_CMD_TILT_UP,"0","50");
}

void SheetView::on_btnUp_released()
{
	ptzControl(PTZ_CMD_TILT_UP, "1", "50");
}

void SheetView::on_btnDown_pressed()
{
	ptzControl(PTZ_CMD_TILT_DOWN, "0", "50");
}

void SheetView::on_btnDown_released()
{
	ptzControl(PTZ_CMD_TILT_DOWN, "1", "50");
}

void SheetView::on_btnLeft_pressed()
{
	ptzControl(PTZ_CMD_PAN_LEFT, "0", "50");
}

void SheetView::on_btnLeft_released()
{
	ptzControl(PTZ_CMD_PAN_LEFT, "1", "50");
}

void SheetView::on_btnRight_pressed()
{
	ptzControl(PTZ_CMD_PAN_RIGHT, "0", "50");
}

void SheetView::on_btnRight_released()
{
	ptzControl(PTZ_CMD_PAN_RIGHT, "1", "50");
}


void SheetView::on_btnLeftUp_pressed()
{
	ptzControl(PTZ_CMD_UP_LEFT, "0", "50");
}

void SheetView::on_btnLeftUp_released()
{
	ptzControl(PTZ_CMD_UP_LEFT, "1", "50");
}

void SheetView::on_btnLeftDown_pressed()
{
	ptzControl(PTZ_CMD_DOWN_LEFT, "0", "50");
}

void SheetView::on_btnLeftDown_released()
{
	ptzControl(PTZ_CMD_DOWN_LEFT, "1", "50");
}

void SheetView::on_btnRightUp_pressed()
{
	ptzControl(PTZ_CMD_UP_RIGHT, "0", "50");
}

void SheetView::on_btnRightUp_released()
{
	ptzControl(PTZ_CMD_UP_RIGHT, "1", "50");
}

void SheetView::on_btnRightDown_pressed()
{
	ptzControl(PTZ_CMD_DOWN_RIGHT, "0", "50");
}

void SheetView::on_btnRightDown_released()
{
	ptzControl(PTZ_CMD_DOWN_RIGHT, "1", "50");
}

//缩放
void SheetView::on_btnZoomIn_pressed()
{
	ptzControl(PTZ_CMD_ZOOM_IN, "0", "50");
}

void SheetView::on_btnZoomIn_released()
{
	ptzControl(PTZ_CMD_ZOOM_IN, "1", "50");
}

void SheetView::on_btnZoomOut_pressed()
{
	ptzControl(PTZ_CMD_ZOOM_OUT, "0", "50");
}

void SheetView::on_btnZoomOut_released()
{
	ptzControl(PTZ_CMD_ZOOM_OUT, "1", "50");
}

//聚焦
void SheetView::on_btnFocusNear_pressed()
{
	ptzControl(PTZ_CMD_FOCUS_NEAR, "0", "50");
}

void SheetView::on_btnFocusNear_released()
{
	ptzControl(PTZ_CMD_FOCUS_NEAR, "1", "50");
}

void SheetView::on_btnFocusFar_pressed()
{
	ptzControl(PTZ_CMD_FOCUS_FAR, "0", "50");
}

void SheetView::on_btnFocusFar_released()
{
	ptzControl(PTZ_CMD_FOCUS_FAR, "1", "50");
}

//光圈
void SheetView::on_btnIrisOpen_pressed()
{
	ptzControl(PTZ_CMD_IRIS_OPEN, "0", "50");
}

void SheetView::on_btnIrisOpen_released()
{
	ptzControl(PTZ_CMD_IRIS_OPEN, "1", "50");
}

void SheetView::on_btnIrisClose_pressed()
{
	ptzControl(PTZ_CMD_IRIS_CLOSE, "0", "50");
}

void SheetView::on_btnIrisClose_released()
{
	ptzControl(PTZ_CMD_IRIS_CLOSE, "1", "50");
}

void SheetView::getResponse()
{
	const QtSoapMessage &response = http.getResponse();
	QString strReturn = response.returnValue().toString();
	switch (serviceType)
	{
	case SERVICE_LOGIN:
		response_sdkLogin(strReturn);
		break;
	case SERVICE_APPLY:
		response_applyToken(strReturn);
		break;
	case SERVICE_PREVIEW:
		response_getPreviewOcxOptions(strReturn);
		break;
	case SERVICE_PLAYBACK:
		response_getPlaybackOcxOptions(strReturn);
		break;
	case SERVICE_ONLYLOHIN:
		response_sdkLogin(strReturn);
		break;
	case SERVICE_GETTOKEN:
		response_setToken(strReturn);
		break;
	default:
		return;
	}

}

void SheetView::NotifyPlatformplaybackctrl(int event_type, int wnd_index, int lparam, QString sparam)
{
	switch (event_type)
	{
	case 0x02000006:
		//serviceType = SERVICE_GETTOKEN;
		{
			tokenId = lparam;
			if (hikTgt == "")
			{
			   service_sdkLogin(SERVICE_ONLYLOHIN);
			}
			else
			{
			   service_applyToken(hikTgt, SERVICE_GETTOKEN);
			}
		}
		break;

	default:
		break;
	}
	return;
}

void SheetView::httpFinished()
{
	QFileInfo fi;
	if (pFile) {
		
		pFile->flush();
		pFile->close();
		pReply->deleteLater();
		pReply = Q_NULLPTR;
		delete pFile;
		pFile = Q_NULLPTR;
	}
	listLYDown.removeAt(0);
	videoDownPlay();
}

void SheetView::httpReadyRead()
{
	if (pFile)
		pFile->write(pReply->readAll());
}

//==============================================================================================================================================

void SheetView::ptzControl(int type, QString strAction, QString strPriority)
{
	QDomDocument doc;
	QDomProcessingInstruction instruction = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");

	doc.appendChild(instruction);

	QDomElement root = doc.createElement("PtzControl");

	QDomElement nodeAction = doc.createElement("Action");
	QDomText textAction = doc.createTextNode(strAction);
	nodeAction.appendChild(textAction);

	QDomElement nodePriority = doc.createElement("Priority");
	QDomText textPriority = doc.createTextNode(strPriority);
	nodePriority.appendChild(textPriority);

	QString strSpeed = ui->comSpeed->currentText();
	QDomElement nodeSpeed = doc.createElement("Speed");
	QDomText textSpeed = doc.createTextNode(strSpeed);
	nodeSpeed.appendChild(textSpeed);

	root.appendChild(nodeAction);
	root.appendChild(nodePriority);
	root.appendChild(nodeSpeed);
	doc.appendChild(root);

	QString strXml = doc.toString();

	ui->axWidgetPreview->dynamicCall("PtzControl(int,QString)", type, strXml);
}

//================================================================================================================================================
void SheetView::initialise()
{
	//ui->stackedWidget->setCurrentIndex(0);
	////initAxWidgetSheet();
	////initPagePlayBack();
	//loader.run(this, &SheetView::loaderSheetVideo);
	//this->setCursor(QCursor(Qt::WaitCursor));

	ui->btnStart->setVisible(false);
	initAxWidgetSheet();
	initPagePreview();
	initPagePlayBack();
	
	initConnect();

	pMusicPlayer = new QMediaPlayer();
	playList = new QMediaPlaylist;
	
	CHK_EXP_RUN(1 == iSheetBox, userLogin());
}

void SheetView::initAxWidgetSheet()
{
	QString strLPUrl = "";
	if (gMapConfigs.contains("VIDEO/LP_URL"))
	{
		strLPUrl = gMapConfigs.value("VIDEO/LP_URL").toString();
	}
	//ui->axWidgetSheet->setControl(QString::fromUtf8("{261F7E9F-970F-484D-996A-E038B1D5F86F}"));
	bool bIsNull = ui->axWidgetSheet->isNull();
	//QString strContent = ui->axWidgetSheet->generateDocumentation();

	LoginUserInfo *pUserInfo = LoginUserInfo::getInstance();
	QString strUserId = pUserInfo->getUserId();
	QString strUserName = pUserInfo->getUserName();
	QString params = strUserId + "|" + strUserName + "|" + QString("%1/servlet/com.sdjxd.pms.platform.webapp.InterFace|%1/resource/dt/|baotou.|").arg(strLPUrl).arg(strLPUrl);
	
	ui->axWidgetSheet->dynamicCall("VideoSetGlobalInfo(QString)", params);

	bool result = ui->axWidgetSheet->dynamicCall("VideoOpenSheet(int, int)", iSheetId, 0).toBool();

}

void SheetView::initPagePreview()
{
	QString strHIKIP = "";
	if (gMapConfigs.contains("VIDEO/HIK_IP"))
	{
		strHIKIP = gMapConfigs.value("VIDEO/HIK_IP").toString();
	}

	QString strHIKPORT = "";
	if (gMapConfigs.contains("VIDEO/HIK_PORT"))
	{
		strHIKPORT = gMapConfigs.value("VIDEO/HIK_PORT").toString();
	}

	bool bIsNull = ui->axWidgetPreview->isNull();
	QString strContent = ui->axWidgetPreview->generateDocumentation();
	ui->axWidgetPreview->setControl(QString::fromUtf8("{6DABF69C-7610-4D25-BC4F-664003130B94}"));
	bIsNull = ui->axWidgetPreview->isNull();
	QString strParam = "<?xml version=\"1.0\" encoding=\"utf - 8\"?>\
					   	<global>\
						<snap picture = \"JPEG\" save = \"E:\snap\" / >\
						<record packSize = \"1024\" save = \"E:\shot\" / >\
						<performance decode = \"5\" / >\
						< / global>";

	ui->axWidgetPreview->dynamicCall("SetGlobalParam(BSTR)", strParam);

	ui->axWidgetPreview->dynamicCall("SetLayoutType(LONG)", 1).toInt();
}

void SheetView::initPagePlayBack()
{
	//ui->axWidgetPlayBack->setControl(QString::fromUtf8("{9fbb8076-0b0e-49f0-9013-7b74b1c4cabb}"));
	bool bIsNull = ui->axWidgetPlayBack->isNull();
	QString strParam = "<?xml version=\"1.0\" encoding=\"utf - 8\"?>\
					   	<global>\
						<snap picture = \"JPEG\" save = \"E:\snap\" / >\
						<record packSize = \"1024\" save = \"E:\shot\" / >\
						<performance decode = \"5\" / >\
						< / global>";

	ui->axWidgetPlayBack->dynamicCall("SetGlobalParam(BSTR)", strParam);
	ui->axWidgetPlayBack->dynamicCall("SetFitLayOut(int)", 1);
	QString strContent = ui->axWidgetPlayBack->generateDocumentation();
}

void SheetView::changePreview(QString strCamIndexCode)
{
	if (strCamIndexCode == strCurrentCamIndex || strCamIndexCode == "null")
	{
		return;
	}
	
	strCurrentCamIndex = strCamIndexCode;
	service_sdkLogin(SERVICE_LOGIN);
}

void SheetView::initSheetCamInfo()
{
	SHEETCAMINFO sheetCamInfo;
	sheetCamInfo.strBeginTime = strStartTime.replace(" ","T");
	QString strDate = strStartTime.left(11);

	QString strCamIndexCode = dsRecordTimer.getCollectStr(0, "CAMINDEXCODE");
	QString strTotalText = dsRecordTimer.getCollectStr(0, "TOTALTEXT");
	QString curTime = strTotalText.mid(strTotalText.lastIndexOf("|") + 1);
	sheetCamInfo.strEndTime = strDate + curTime;
	sheetCamInfo.strCamIndexCode = strCamIndexCode;

	for (int i = 1; i < dsRecordTimer.rowCount(); i++)
	{
		strCamIndexCode=dsRecordTimer.getCollectStr(i, "CAMINDEXCODE");
		strTotalText = dsRecordTimer.getCollectStr(i, "TOTALTEXT");
		curTime = strTotalText.mid(strTotalText.lastIndexOf("|") + 1);
		if (strCamIndexCode == sheetCamInfo.strCamIndexCode)
		{
			sheetCamInfo.strEndTime = strDate + curTime;
		}
		else
		{
			listSheetCamInfo.append(sheetCamInfo);
			sheetCamInfo.strBeginTime = sheetCamInfo.strEndTime;
			sheetCamInfo.strEndTime = strDate + curTime;
			sheetCamInfo.strCamIndexCode = strCamIndexCode;
		}
	}
	listSheetCamInfo.append(sheetCamInfo);
}

void SheetView::service_sdkLogin(WEBSERVICE_TYPE iServiceType)
{
	serviceType = iServiceType;
	if (hikTgt != "")
	{
		if (SERVICE_ONLYLOHIN == iServiceType)
		{
			return;
		}
		service_applyToken(hikTgt, SERVICE_APPLY);
		return;
	}
	QString strHIKIP = "";
	QString strHIKUserName = "";
	QString strHIKPwd = "";
	if (gMapConfigs.contains("VIDEO/HIK_IP"))
	{
		strHIKIP = gMapConfigs.value("VIDEO/HIK_IP").toString();
	}

	if (gMapConfigs.contains("VIDEO/HIK_USERNAME"))
	{
		strHIKUserName = gMapConfigs.value("VIDEO/HIK_USERNAME").toString();
	}

	if (gMapConfigs.contains("VIDEO/HIK_PWD"))
	{
		strHIKPwd = gMapConfigs.value("VIDEO/HIK_PWD").toString();
	}
	QtSoapMessage request;
	//设置方法
	QString strSha256Pwd;
	QByteArray bb;
	bb = QCryptographicHash::hash(strHIKPwd.toLocal8Bit(), QCryptographicHash::Sha256);
	strSha256Pwd.append(bb.toHex());

	request.setMethod("sdkLogin", "http://ws.vms.ivms6.hikvision.com");
	request.addMethodArgument("loginAccount", "", strHIKUserName);
	request.addMethodArgument("password", "", strSha256Pwd);
	request.addMethodArgument("serviceIp", "", strHIKIP);
	request.addMethodArgument("clientIp", "", "");
	request.addMethodArgument("clientMac", "", "");
	QString strXML = request.toXmlString();

	//设置主机
	http.setHost(strHIKIP);

	//设置动作
	http.setAction("http://ws.vms.ivms6.hikvision.com/sdkLogin");

	// 提交请求
	http.submitRequest(request, "/vms/services/VmsSdkWebService");
	
}

void SheetView::service_applyToken(QString tgt, WEBSERVICE_TYPE iServiceType)
{
	serviceType = iServiceType;
	QString strHIKIP = "";
	if (gMapConfigs.contains("VIDEO/HIK_IP"))
	{
		strHIKIP = gMapConfigs.value("VIDEO/HIK_IP").toString();
	}
	QtSoapMessage request;
	//设置方法
	request.setMethod("applyToken", "http://ws.vms.ivms6.hikvision.com");
	request.addMethodArgument("tgc", "", tgt);

	QString strXML = request.toXmlString();

	//设置主机
	http.setHost(strHIKIP);

	//设置动作
	http.setAction("http://ws.vms.ivms6.hikvision.com/applyToken");

	// 提交请求
	http.submitRequest(request, "/vms/services/VmsSdkWebService");
}

void SheetView::service_getPreviewOcxOptions(QString token, QString cameraIndexCode)
{
	serviceType = SERVICE_PREVIEW;
	QString strHIKIP = "";
	if (gMapConfigs.contains("VIDEO/HIK_IP"))
	{
		strHIKIP = gMapConfigs.value("VIDEO/HIK_IP").toString();
	}
	QtSoapMessage request;
	//设置方法
	request.setMethod("getPreviewOcxOptions", "http://ws.vms.ivms6.hikvision.com");
	request.addMethodArgument("token", "", token);
	request.addMethodArgument("cameraIndexCode", "", cameraIndexCode);
	request.addMethodArgument("clientIp", "", strHIKIP);

	QString strXML = request.toXmlString();

	//设置主机
	http.setHost(strHIKIP);

	//设置动作
	http.setAction("http://ws.vms.ivms6.hikvision.com/getPreviewOcxOptions");

	// 提交请求
	http.submitRequest(request, "/vms/services/VmsSdkWebService");
}

void SheetView::service_getPlaybackOcxOptions(QString token, QString cameraIndexCode, QString beginTime, QString endTime, QString storeDeviceType)
{
	serviceType = SERVICE_PLAYBACK;
	QString strHIKIP = "";
	if (gMapConfigs.contains("VIDEO/HIK_IP"))
	{
		strHIKIP = gMapConfigs.value("VIDEO/HIK_IP").toString();
	}
	QtSoapMessage request;
	//设置方法
	request.setMethod("getPlaybackOcxOptions", "http://ws.vms.ivms6.hikvision.com");
	request.addMethodArgument("token", "", token);
	request.addMethodArgument("cameraIndexCode", "", cameraIndexCode);
	request.addMethodArgument("clientIp", "", strHIKIP);
	request.addMethodArgument("beginTime", "", beginTime+"Z");
	request.addMethodArgument("endTime", "", endTime+"Z");
	request.addMethodArgument("storeDeviceType", "", storeDeviceType);

	QString strXML = request.toXmlString();

	//设置主机
	http.setHost(strHIKIP);

	//设置动作
	http.setAction("http://ws.vms.ivms6.hikvision.com/getPlaybackOcxOptions");

	// 提交请求
	http.submitRequest(request, "/vms/services/VmsSdkWebService");
}

void SheetView::response_sdkLogin(QString strReturn)
{
	QDomDocument doc;
	doc.setContent(strReturn);

	QDomNodeList &nodeListResult = doc.elementsByTagName("result");
	if (nodeListResult.count() != 0)
	{
		QDomNode nodeHead = nodeListResult.at(0);
		if (!nodeHead.isElement())
		{
			qMsgBoxAlert(tr("HIK name or password is failed!"));
			return;
		}
		int iResult = nodeHead.toElement().attribute("result_code").toInt();
		if (0 != iResult)
		{
			qMsgBoxAlert(tr("HIK name or password is failed!"));
			return;
		}

		QDomNodeList &nodeListRow = doc.elementsByTagName("row");
		if (nodeListRow.count() != 0)
		{
			QDomNode nodeTgt = nodeListRow.at(0);
			if (!nodeTgt.isElement())
			{
				return;
			}
			QString tgt = nodeTgt.toElement().attribute("tgt");
			hikTgt = tgt;
			if (serviceType == SERVICE_LOGIN)
			{
				service_applyToken(tgt, SERVICE_APPLY);
			}
			if (serviceType == SERVICE_ONLYLOHIN)
			{
				service_applyToken(tgt, SERVICE_ONLYLOHIN);
			}
		}
	}
}

void SheetView::response_applyToken(QString strReturn)
{
	QDomDocument doc;
	doc.setContent(strReturn);

	QDomNodeList &nodeListResult = doc.elementsByTagName("result");
	if (nodeListResult.count() != 0)
	{
		QDomNode nodeHead = nodeListResult.at(0);
		if (!nodeHead.isElement())
		{
			qMsgBoxAlert(tr("apply toke failed!"));
			return;
		}
		int iResult = nodeHead.toElement().attribute("result_code").toInt();
		if (0 != iResult)
		{
			qMsgBoxAlert(tr("apply toke failed!"));
			return;
		}

		QDomNodeList &nodeListRow = doc.elementsByTagName("row");
		if (nodeListRow.count() != 0)
		{
			QDomNode nodeSt = nodeListRow.at(0);
			if (!nodeSt.isElement())
			{
				return;
			}
			QString st = nodeSt.toElement().attribute("st");
			if (ui->stackedWidget->currentIndex()==0)
			{
				service_getPreviewOcxOptions(st, strCurrentCamIndex);
			}
			else
			{
				SHEETCAMINFO &camInfoOne = listSheetCamInfo[0];
				service_getPlaybackOcxOptions(st, strCurrentCamIndex, camInfoOne.strBeginTime, camInfoOne.strEndTime, "0");
				//service_getPlaybackOcxOptions(st, "001384", "2017-01-05T00:00:00", "2017-01-05T23:59:59", "0");
			}
			
		}

	}
}

void SheetView::response_getPreviewOcxOptions(QString strReturn)
{
	ui->axWidgetPreview->dynamicCall("StartPreview(QString, int)", strReturn, 0);
}

void SheetView::response_getPlaybackOcxOptions(QString strReturn)
{

	//QMessageBox::information(this, QString::fromLocal8Bit("警告"), strReturn);
	SHEETCAMINFO &camInfoOne = listSheetCamInfo[0];
	ui->axWidgetPlayBack->dynamicCall("SetPlayback(QString, QString, Qstring)", camInfoOne.strBeginTime+"Z", camInfoOne.strEndTime+"Z", strReturn);
}

void SheetView::response_setToken(QString strReturn)
{
	QDomDocument doc;
	doc.setContent(strReturn);

	QDomNodeList &nodeListResult = doc.elementsByTagName("result");
	if (nodeListResult.count() != 0)
	{
		QDomNode nodeHead = nodeListResult.at(0);
		if (!nodeHead.isElement())
		{
			qMsgBoxAlert(tr("apply toke failed!"));
			return;
		}
		int iResult = nodeHead.toElement().attribute("result_code").toInt();
		if (0 != iResult)
		{
			qMsgBoxAlert(tr("apply toke failed!"));
			return;
		}

		QDomNodeList &nodeListRow = doc.elementsByTagName("row");
		if (nodeListRow.count() != 0)
		{
			QDomNode nodeSt = nodeListRow.at(0);
			if (!nodeSt.isElement())
			{
				return;
			}
			QString st = nodeSt.toElement().attribute("st");
			ui->axWidgetPlayBack->dynamicCall("SetToken(int, QString)", tokenId, st);
		}

	}
}

void SheetView::startRequest()
{
	CHK_EXP_END(listLY.count() == 0);
	for (int i = 0; i < listLY.count();i++)
	{
		QFile file(createVideoPath(listLY[i], false));
		if (!file.exists())
		{
			listLYDown.append(listLY[i]);
		}
	}
	videoDownPlay();
}

void SheetView::videoDownPlay()
{
	if (listLYDown.count() == 0)
	{
		playList->clear();
		playList->setPlaybackMode(QMediaPlaylist::Sequential);
		for (int i = 0; i < listLY.count(); i++)
		{
			playList->addMedia(QUrl::fromLocalFile(createVideoPath(listLY[i], false)));
		}
		pMusicPlayer->setMedia(playList);
		pMusicPlayer->setVolume(80);
		pMusicPlayer->play();

		QString strFirstFileName = listLY[0];
		qlonglong imsec = strFirstFileName.mid(strFirstFileName.indexOf("-") + 1).toLongLong();
		QDateTime dtStartTime;
		dtStartTime.setMSecsSinceEpoch(imsec);
		strStartTime = dtStartTime.toString("yyyy-MM-dd hh:mm:ss");
	
		QString sql = QString("SELECT SORTID,TOTALTEXT,CAMINDEXCODE FROM WS_CZPTEXT WHERE SHEETID=%1 ORDER BY SORTID").arg(iSheetId);
		dsRecordTimer.select(sql);

		iCurrentRow = 0;
		CHK_EXP_END(iCurrentRow >= dsRecordTimer.rowCount());
		initSheetCamInfo();

		QString strCamIndexCode = dsRecordTimer.getCollectStr(iCurrentRow, "CAMINDEXCODE");
		int iSortId = dsRecordTimer.getCollectInt(iCurrentRow, "SORTID");
		QString strTotalText = dsRecordTimer.getCollectStr(iCurrentRow, "TOTALTEXT");
		int iLastIndex = strTotalText.lastIndexOf("|");
		QString curTime = strTotalText.mid(iLastIndex + 1);
		QTime tTime = QTime::fromString(curTime, "hh:mm:ss");

		int iTime = dtStartTime.time().msecsTo(tTime);
		tCurBeginTime = tTime;
		strCurrentCamIndex = strCamIndexCode;

		ui->axWidgetSheet->dynamicCall("SetCurrentSelectRow(int,int)", iSheetId, iSortId);
		service_sdkLogin(SERVICE_LOGIN);
		iTimerId = startTimer(iTime);
		return;
	}

	QString strFileName = listLYDown[0];
	pFile = new QFile(createVideoPath(strFileName, false));

	if (!pFile->open(QIODevice::WriteOnly))
	{
		return;
	}
	QUrl url(createVideoPath(strFileName, true));
	pReply = qnam.get(QNetworkRequest(url));
	connect(pReply, &QNetworkReply::finished, this, &SheetView::httpFinished);
	connect(pReply, &QIODevice::readyRead, this, &SheetView::httpReadyRead);
}

QString SheetView::createVideoPath(QString fileName, bool bURL)
{
	if (bURL)
	{
		static QString strLPUrl;
		if ((strLPUrl.isEmpty()||strLPUrl.isNull())&&gMapConfigs.contains("VIDEO/LP_URL"))
		{
			strLPUrl = gMapConfigs.value("VIDEO/LP_URL").toString();
		}
		return strLPUrl+"/resource/dt/" + fileName+".mp3";
	}
	else
	{
		QDir dir;
		static QString videoPath;
		if (videoPath.isEmpty() || videoPath.isNull())
		{
			videoPath = QDir(QCoreApplication::applicationDirPath() + "/..").canonicalPath() + "/res/images/video/";
		}
		//判断目录是否存在并创建目录
		CHK_EXP_RUN(!dir.exists(videoPath), dir.mkpath(videoPath));

		return videoPath + fileName + ".mp3";
	}

}


//=========================================================================================================================================

//初始化
void SheetView::initConnect()
{
	m_AnyChatSDK.LoadFilterDll(L"BRAnyChatCore.dll");  //利用对象加载动态库

	//获取SDK的版本信息
	DWORD dwMainVer, dwSubVer;
	char szCompileTime[100] = { 0 };
	m_AnyChatSDK.GetSDKVersion(dwMainVer, dwSubVer, szCompileTime, sizeof(szCompileTime));


	//打开（关闭）SDK的日志记录功能
	m_AnyChatSDK.ActiveCallLog(true);

	//设置SDK核心组件所在目录（注：demo程序只是设置为当前目录，项目中需要设置为实际路径）
	QString szCoreSDKPath;
	szCoreSDKPath = QCoreApplication::applicationDirPath();   //获取当前应用程序路径
	(strrchr((char*)szCoreSDKPath.toStdString().c_str(), '/'))[1] = 0;
	m_AnyChatSDK.SetSDKOption(BRAC_SO_CORESDK_PATH, (char*)szCoreSDKPath.toStdString().c_str(), strlen((char*)szCoreSDKPath.toStdString().c_str()));

	// 根据BRAC_InitSDK的第二个参数：dwFuncMode，来告诉SDK该如何处理相关的任务（详情请参考开发文档）
	/*DWORD dwFuncMode = BRAC_FUNC_VIDEO_AUTODISP | BRAC_FUNC_AUDIO_AUTOPLAY | BRAC_FUNC_CHKDEPENDMODULE |
	BRAC_FUNC_AUDIO_VOLUMECALC | BRAC_FUNC_NET_SUPPORTUPNP | BRAC_FUNC_FIREWALL_OPEN |
	BRAC_FUNC_AUDIO_AUTOVOLUME | BRAC_FUNC_AUDIO_VOLUMECALC | BRAC_FUNC_CONFIG_LOCALINI;*/

	DWORD dwFuncMode = BRAC_FUNC_AUDIO_AUTOPLAY | BRAC_FUNC_CHKDEPENDMODULE |
		BRAC_FUNC_AUDIO_VOLUMECALC | BRAC_FUNC_NET_SUPPORTUPNP | BRAC_FUNC_FIREWALL_OPEN |
		BRAC_FUNC_AUDIO_AUTOVOLUME | BRAC_FUNC_AUDIO_VOLUMECALC | BRAC_FUNC_CONFIG_LOCALINI;

	m_AnyChatSDK.InitSDK((HWND)this->winId(), dwFuncMode);
	//m_AnyChatSDK.SetVideoDataCallBack(BRAC_PIX_FMT_RGB24,VideoData_CallBack, this);//设置视频数据回调函数
	//m_AnyChatSDK.SetAudioDataCallBack(AudioData_CallBack, this);//设置音频数据回调函数
	//m_AnyChatSDK.SetVolumeChangeCallBack(VolumeChange_CallBack, this);//设置音量变化回调函数
	m_AnyChatSDK.SetTextMessageCallBack(TextMessage_CallBack,this);//设置文字消息回调函数
	//m_AnyChatSDK.SetTransBufferExCallBack(TransBufferEx_CallBack, this);//设置透明通道数据扩展回调函数
	// m_AnyChatSDK.SetTransBufferCallBack(TransBuffer_CallBack, this);//设置透明通道数据回调函数
	// m_AnyChatSDK.SetTransFileCallBack(TransFile_CallBack, this);//设置文件传输回调函数
	// m_AnyChatSDK.SetRecordSnapShotCallBack(RecordSnapShot_CallBack, this);//设置录像快照回调函数
	m_AnyChatSDK.SetSDKFilterDataCallBack(SDKFilterData_CallBack, this);//设置sdk filter通信数据回调函数
	m_AnyChatSDK.SetNotifyMessageCallBack(NotifyMessage_CallBack, this);//设置异步消息通知回调函数
	// m_AnyChatSDK.SetTimerProcCallBack(TimerProc_CallBack, this);

	m_bEnableVAD = true; //获得四个复选框的值
	m_bEnableAGC = true;
	m_bEnableEcho = true;
	m_bEnableNS = true;

	m_AnyChatSDK.SetSDKOption(BRAC_SO_AUDIO_AGCCTRL, (PCHAR)&m_bEnableAGC, sizeof(m_bEnableAGC));//音频自动增益控制
	m_AnyChatSDK.SetSDKOption(BRAC_SO_AUDIO_VADCTRL, (PCHAR)&m_bEnableVAD, sizeof(m_bEnableVAD));//音频静音检测控制
	m_AnyChatSDK.SetSDKOption(BRAC_SO_AUDIO_NSCTRL, (PCHAR)&m_bEnableNS, sizeof(m_bEnableNS));//音频噪音抑制控制
	m_AnyChatSDK.SetSDKOption(BRAC_SO_AUDIO_ECHOCTRL, (PCHAR)&m_bEnableEcho, sizeof(m_bEnableEcho));//音频回音消除控制

	// 设置录像临时文件保存路径
	QString szRecordDirectory;
	szRecordDirectory = QCoreApplication::applicationDirPath();   //获取当前就用程序路径
	(strrchr((char*)szRecordDirectory.toStdString().c_str(), '/'))[1] = 0;
	szRecordDirectory.append("/Record");
	m_AnyChatSDK.SetSDKOption(BRAC_SO_RECORD_TMPDIR, (char*)szRecordDirectory.toStdString().c_str(), strlen((char*)szRecordDirectory.toStdString().c_str()));

	// 设置录像文件质量参数
	DWORD dwVideoBitrate = 200 * 1000;	// 200kbps
	m_AnyChatSDK.SetSDKOption(BRAC_SO_RECORD_VIDEOBR, (PCHAR)&dwVideoBitrate, sizeof(DWORD));
	DWORD dwAudioBitrate = 96 * 1000;	// 96kbps
	m_AnyChatSDK.SetSDKOption(BRAC_SO_RECORD_AUDIOBR, (PCHAR)&dwAudioBitrate, sizeof(DWORD));

	// 设置快照临时文件保存路径
	QString szSnapShotDirectory;
	szSnapShotDirectory = QCoreApplication::applicationDirPath();   //获取当前应用程序路径
	(strrchr((char*)szSnapShotDirectory.toStdString().c_str(), '/'))[1] = 0;
	szSnapShotDirectory.append("/SnapShot");
	m_AnyChatSDK.SetSDKOption(BRAC_SO_SNAPSHOT_TMPDIR, (char*)szSnapShotDirectory.toStdString().c_str(), strlen((char*)szSnapShotDirectory.toStdString().c_str()));

	// 设置SDK临时文件路径
	QString szTempPath;
	szTempPath = QCoreApplication::applicationDirPath();   //获取当前就用程序路径
	(strrchr((char*)szTempPath.toStdString().c_str(), '/'))[1] = 0;
	szTempPath.append("/SnapShot");
	m_AnyChatSDK.SetSDKOption(BRAC_SO_CORESDK_TMPDIR, (char*)szTempPath.toStdString().c_str(), strlen((char*)szTempPath.toStdString().c_str()));

	// 设置服务器认证密码
	QString pwd = "BaiRuiTech";
	m_AnyChatSDK.SetServerAuthPass((LPCTSTR)pwd.toStdString().c_str());

	m_UserRect[0].setRect(9, 380, 170, 140);
	m_UserRect[1].setRect(190, 380, 170, 140);
	m_UserRect[2].setRect(370, 380, 170, 140);
	m_UserRect[3].setRect(550, 380, 170, 140);
}

//用户登录
void SheetView::userLogin()
{
	bool ok;
	QString strServerIp = "127.0.0.1";           //IP地址
	QString strUserName = "Admin2";         //用户名
	QString strPassword = "";          //密码
	int intPort = 8906;      //端口号由字符串格式转换为整型格式

	if (gMapConfigs.contains("VIDEO/ANYCHAT_IP"))
	{
		strServerIp = gMapConfigs.value("VIDEO/ANYCHAT_IP").toString();
	}

	if (gMapConfigs.contains("VIDEO/ANYCHAT_PORT"))
	{
		intPort = gMapConfigs.value("VIDEO/ANYCHAT_PORT").toInt();
	}

	int ret = m_AnyChatSDK.Connect((LPCTSTR)strServerIp.toStdString().c_str(), intPort);   //？用GetBuffer
	ret = m_AnyChatSDK.Login((LPCTSTR)strUserName.toStdString().c_str(), (LPCTSTR)strPassword.toStdString().c_str(), 0);
}

//进入房间
void SheetView::enterRoom()
{
	QString roomId = "1";
	QString pwd = "";
	int ret = m_AnyChatSDK.EnterRoom(iSheetId, (LPCTSTR)pwd.toStdString().c_str(), 0);
}

//离开房间
void SheetView::leaveRoom()
{
	m_AnyChatSDK.LeaveRoom(iSheetId);
	//保留自己的userid, 因为这儿只是leaveroom, 并非logout
	for (int i = 1; i < DEMO_SHOW_USER_NUM; i++)
	{
		m_iUserID[i] = -1;
	}
}

//=====================================================================================================================================
// 收到消息：客户端连接服务器 wParam（BOOL）表示是否连接成功
LRESULT SheetView::OnGVClientConnect(WPARAM wParam, LPARAM lParam)
{
	enterRoom();
	return 0;
}

// 收到消息：客户端登录系统 wParam （INT）表示自己的用户ID号, lParam （INT）表示登录结果：0 成功，否则为出错代码，参考出错代码定义
LRESULT SheetView::OnGVClientLogin(WPARAM wParam, LPARAM lParam)
{
	QString logstr;
	DWORD dwUserID = wParam;
	if (lParam == 0)
	{
		CHAR username[30];
		m_AnyChatSDK.GetUserName(dwUserID, username, sizeof(username));
		logstr.sprintf("登录服务器成功，自己的用户编号为：%d(%s)", wParam, username);
	}
	else
	{
		qMsgBoxError("login failed!");
		logstr.sprintf("登录服务器失败，出错代码为： %d ", lParam);
	}
		

	return 0;
}

// 收到消息：客户端进入房间  wParam （INT）表示所进入房间的ID号,lParam （INT）表示是否进入房间：0成功进入，否则为出错代码
LRESULT SheetView::OnGVClientEnterRoom(WPARAM wParam, LPARAM lParam)
{
	QString logstr;
	INT roomid = (INT)wParam;
	if (lParam == 0)
	{
		logstr.sprintf("成功进入编号为：%d 的房间", roomid);

		m_AnyChatSDK.SetVideoPos(-1, (HWND)this->winId(), m_UserRect[0].left(), m_UserRect[0].top(), m_UserRect[0].right(), m_UserRect[0].bottom());
		m_AnyChatSDK.UserCameraControl(-1, FALSE);
		m_AnyChatSDK.UserSpeakControl(-1, TRUE);
		qMsgBoxInfo("enter room successed!");

		const char* info = "##观众##";
		if ((m_AnyChatSDK.SendTextMessage(-1, NULL, (LPCTSTR)info, sizeof(*info))) != 0)  //发送成功
		{
			qMsgBoxInfo("get operator failed!");
		}
	}
	else
	{
		logstr.sprintf("申请进入房间失败，出错代码为： %d ", lParam);
		qMsgBoxError("enter room failed!");
	}

	return 0;
}

// 收到当前房间的在线用户信息 wParam （INT）表示在线用户数（不包含自己）,lParam （INT）表示房间ID
LRESULT SheetView::OnGVClientOnlineUser(WPARAM wParam, LPARAM lParam)
{
	QString logstr;
	int onlinenum = (int)wParam;

	DWORD dwUserNum = 0;
	m_AnyChatSDK.GetOnlineUser(NULL, dwUserNum);      //首先获取房间内在线人数
	if (!dwUserNum)
		return 0;

	LPDWORD lpdwUserList = (LPDWORD)malloc(sizeof(DWORD)*dwUserNum);
	m_AnyChatSDK.GetOnlineUser(lpdwUserList, dwUserNum);

	for (int i = 0; i < (int)dwUserNum; i++)
	{
		DWORD userid = lpdwUserList[i];
		// 给用户找一个空的位置显示面板（第0号位置留给自己）
		INT site = -1;
		for (INT i = 1; i < DEMO_SHOW_USER_NUM; i++)
		{
			if (m_iUserID[i] == -1)
			{
				site = i;
				break;
			}
		}
		if (site != -1)
		{
			m_AnyChatSDK.SetVideoPos(userid,(HWND)this->winId(), m_UserRect[site].left(), m_UserRect[site].top(), m_UserRect[site].right(), m_UserRect[site].bottom());
			m_AnyChatSDK.UserCameraControl(userid, FALSE);
			m_AnyChatSDK.UserSpeakControl(userid, TRUE);

			DWORD dwState = 0;
			m_AnyChatSDK.GetCameraState(userid, dwState);
			logstr.sprintf("用户%d的视频状态是：%d", userid, dwState);

			m_iUserID[site] = userid;
		}
		else
			break;
	}
	free(lpdwUserList);
	return 0;
}

// 收到消息：用户的音频设备状态变化消息  wParam （INT）表示用户ID号 lParam （BOOL）表示该用户是否已打开音频采集设备
LRESULT SheetView::OnGVClientMicStateChange(WPARAM wParam, LPARAM lParam)
{
	return 0;
}

// 收到消息：用户进入（离开）房间 wParam （INT）表示用户ID号,lParam （BOOL）表示该用户是进入（TRUE）或离开（FALSE）房间
LRESULT SheetView::OnGVClientUserAtRoom(WPARAM wParam, LPARAM lParam)
{
	QString logstr;
	int userid = (int)wParam;
	bool bEnter = (bool)lParam;

	char username[30] = { 0 };
	m_AnyChatSDK.GetUserName(userid, username, sizeof(username));

	if (bEnter)
	{
		// 给用户找一个空的位置显示面板（第0号位置留给自己）
		int site = -1;
		for (INT i = 1; i < DEMO_SHOW_USER_NUM; i++)
		{
			if (m_iUserID[i] == -1)
			{
				site = i;
				break;
			}
		}
		if (site != -1)
		{
			m_AnyChatSDK.SetVideoPos(userid, (HWND)this->winId(), m_UserRect[site].left(), m_UserRect[site].top(), m_UserRect[site].right(), m_UserRect[site].bottom());
			m_AnyChatSDK.UserCameraControl(userid, FALSE);
			m_AnyChatSDK.UserSpeakControl(userid, TRUE);
			m_iUserID[site] = userid;
		}
	}
	else
	{
		//清除该用户占用位置的信息
		for (INT i = 1; i < DEMO_SHOW_USER_NUM; i++)
		{
			if (m_iUserID[i] == userid)
			{
				m_iUserID[i] = -1;
				break;
			}
		}
	}
	return 0;
}

//收到消息：网络连接已关闭    (该消息只有在客户端连接服务器成功之后，网络异常中断之时触发)
LRESULT SheetView::OnGVClientLinkClose(WPARAM wParam, LPARAM lParam)
{
	for (INT i = 0; i < DEMO_SHOW_USER_NUM; i++)
	{
		m_iUserID[i] = -1;
	}
	return 0;
}

//用户聊天模式发生变化  wParam （INT）表示用户ID号,lParam （INT）表示用户的当前聊天模式
LRESULT SheetView::OnGVClientChatModeChange(WPARAM wParam, LPARAM lParam)
{
	return 0;
}

// SDK Filter 通信数据回调函数定义
void CALLBACK SheetView::SDKFilterData_CallBack(LPBYTE lpBuf, DWORD dwLen, LPVOID lpUserValue)
{
	SheetView*	pDemoDlg = (SheetView*)lpUserValue;
	QString message;
	if (pDemoDlg)
	{
		message.sprintf("%s", lpBuf);
		QJsonParseError error;
		QByteArray byte = message.toLocal8Bit();
		const QJsonDocument & jsonDoc = QJsonDocument::fromJson(byte, &error);
		if (jsonDoc.isObject())
		{
			const QJsonObject & jsonObject = jsonDoc.object();
			if (jsonObject.contains("actionType"))
			{
				int actionType = jsonObject["actionType"].toInt();
				if (0==actionType)
				{
					//QString strRoomOwner = QString(tr("executor:")) + jsonObject["roomOwner"].toString();
					//qMsgBoxInfo(strRoomOwner);
				}
				else if (2==actionType)
				{
					pDemoDlg->ui->axWidgetSheet->dynamicCall("SetMakeSheetCurrentRow(QString)", jsonObject["action"].toString());
				}
				else if (3 == actionType)
				{
					QString strText = pDemoDlg->strPreviousSelectText;
					if (pDemoDlg->strPreviousSelectText == "")
					{
						strText = jsonObject["text"].toString();
					}
					pDemoDlg->strPreviousSelectText = jsonObject["text"].toString();
					
					int iIndexOne = strText.indexOf("@");
					int iIndexTwo = strText.indexOf("@", iIndexOne + 1);
					QString strCamIndexCode = strText.left(strText.indexOf("@", 2));
					QString strContent = strText.mid(iIndexTwo + 1);
					pDemoDlg->changePreview(strCamIndexCode);
					pDemoDlg->ui->axWidgetSheet->dynamicCall("SetMakeSheetCurrentRow(QString)", strContent);
				}
			}
		}
	}
}

// 文字消息回调函数定义
void CALLBACK SheetView::TextMessage_CallBack(DWORD dwFromUserid, DWORD dwToUserid, BOOL bSecret, LPCTSTR lpMsgBuf, DWORD dwLen, LPVOID lpUserValue)
{
	SheetView*	pDemoDlg = (SheetView*)lpUserValue;
	QString message;
	if (pDemoDlg)
	{
	
	}
}

// 异步消息通知回调函数定义
void CALLBACK SheetView::NotifyMessage_CallBack(DWORD dwNotifyMsg, DWORD wParam, DWORD lParam, LPVOID lpUserValue)
{
	//BR_AFX_MANAGE_STATE;
	SheetView*	pAnyChatSDKProc = (SheetView*)lpUserValue;
	if (!pAnyChatSDKProc)
		return;
	switch (dwNotifyMsg)
	{
	case WM_GV_CONNECT:		pAnyChatSDKProc->OnGVClientConnect(wParam, NULL);		break;
	case WM_GV_LOGINSYSTEM:		pAnyChatSDKProc->OnGVClientLogin(wParam, lParam);                break;
	case WM_GV_ENTERROOM:           pAnyChatSDKProc->OnGVClientEnterRoom(wParam, lParam);            break;
	case WM_GV_MICSTATECHANGE:	pAnyChatSDKProc->OnGVClientMicStateChange(wParam, lParam);       break;
	case WM_GV_USERATROOM:		pAnyChatSDKProc->OnGVClientUserAtRoom(wParam, lParam);           break;
	case WM_GV_LINKCLOSE:           pAnyChatSDKProc->OnGVClientLinkClose(wParam, lParam);           break;
	case WM_GV_ONLINEUSER:		pAnyChatSDKProc->OnGVClientOnlineUser(wParam, lParam);           break;

	case WM_GV_CAMERASTATE:		pAnyChatSDKProc->OnAnyChatCameraStateChgMessage(wParam, lParam);	break;
	case WM_GV_CHATMODECHG:		pAnyChatSDKProc->OnGVClientChatModeChange(wParam, lParam);       break;
	case WM_GV_ACTIVESTATE:		pAnyChatSDKProc->OnAnyChatActiveStateChgMessage(wParam, lParam);	break;
	case WM_GV_P2PCONNECTSTATE:	pAnyChatSDKProc->OnAnyChatP2PConnectStateMessage(wParam, lParam); break;

	case WM_GV_PRIVATEREQUEST:	pAnyChatSDKProc->OnAnyChatPrivateRequestMessage(wParam, lParam);	break;
	case WM_GV_PRIVATEECHO:		pAnyChatSDKProc->OnAnyChatPrivateEchoMessage(wParam, lParam);	break;
	case WM_GV_PRIVATEEXIT:		pAnyChatSDKProc->OnAnyChatPrivateExitMessage(wParam, lParam);	break;

	case WM_GV_SDKWARNING:		pAnyChatSDKProc->OnAnyChatSDKWarningMessage(wParam, lParam);     break;

	default:
		break;
	}
	pAnyChatSDKProc->OnAnyChatNotifyMessageCallBack(dwNotifyMsg, wParam, lParam);
};


